﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CreaMotion.ValueConverters
{
	public class String2Table:IValueConverter
	{
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //String 2 Table
            Interfaces.Table ReturnData = new Interfaces.Table();

            try
            {
                List<Interfaces.Table> tables = (List<Interfaces.Table>)parameter;
                ReturnData = tables.Find(delegate(Interfaces.Table table) { return table.TableName == (string)value; });
            }
            catch { }

            return ReturnData;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //Table 2 String
            string returnData = string.Empty;

            try
            {
                returnData = ((Interfaces.Table)value).TableName;
            }
            catch {}

            return returnData;
        }
    }
}